﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.SERVICE.DAL;

namespace KPIS.GERP.SERVICE.Demo.Ekk.MySampleFlow.UserControls
{
    public partial class AbsenceRequestForm : System.Web.UI.UserControl
    {
        private Absence absenceDAL = new Absence();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadAbsenceType();
                LoadTimePeriod();
                cmbRadEndTimePeriod.SelectedIndex = 1;
            }
            DataBind();
            if (!Page.IsPostBack)
            {
                cmbRadEndTimePeriod.SelectedIndex = 1;
            }
        }

        private void LoadTimePeriod()
        {
            cmbRadStartTimePeriod.DataSource = TimePeriodData;
            cmbRadStartTimePeriod.DataBind();
            cmbRadEndTimePeriod.DataSource = TimePeriodData;
            cmbRadEndTimePeriod.DataBind();
        }

        private void LoadAbsenceType()
        {
            var datasource = absenceDAL.GetHrmPsAbsenceType(null);
            cmbAbsenceType.DataSource = datasource;
            cmbAbsenceType.DataBind();
        }

        public string AbsenceType
        {
            get { return cmbAbsenceType.SelectedValue; }
            set { cmbAbsenceType.SelectedValue = value; }
        }

        public DateTime? DateStart
        {
            get { return dtpRadStartDate.SelectedDate; }
            set { dtpRadStartDate.SelectedDate = value; }
        }

        public DateTime? DateEnd
        {
            get { return dtpRadEndDate.SelectedDate; }
            set { dtpRadEndDate.SelectedDate = value; }
        }

        public string TimePeriodStart
        {
            get { return cmbRadStartTimePeriod.SelectedValue; }
            set { cmbRadStartTimePeriod.SelectedValue = value; }
        }

        public string TimePeriodEnd
        {
            get { return cmbRadEndTimePeriod.SelectedValue; }
            set { cmbRadEndTimePeriod.SelectedValue = value; }
        }

        public string CurrentEmpSeq
        {
            get { return hdfEmpSeq.ToString(); }
            set { hdfEmpSeq.Value = value; }
        }

        public string ViewMode
        {
            get { return hdfViewMode.Value; }
            set { hdfViewMode.Value = value; }
        }

        public string Remark
        {
            get { return txtRadRemarks.Text; }
            set { txtRadRemarks.Text = value; }
        }

        public Dictionary<string, string> TimePeriodData = new Dictionary<string, string>
            {{"ช่วงเช้า", "M"}, {"ช่วงบ่าย", "A"}};

        public bool CheckValidate(out string errorStr)
        {
            StringBuilder errorStrb = new StringBuilder();
            if (String.IsNullOrEmpty(AbsenceType))
                errorStrb.Append(String.Format("AbsenceType is Empty"));
            if (DateStart == null)
                errorStrb.Append(String.Format("DateStart is null"));
            if (DateEnd == null)
                errorStrb.Append(String.Format("DateEnd is null"));
            if (String.IsNullOrEmpty(TimePeriodStart))
                errorStrb.Append(String.Format("TimePeriodStart is Empty"));
            if (String.IsNullOrEmpty(TimePeriodEnd))
                errorStrb.Append(String.Format("TimePeriodEnd is Empty"));
            if (String.IsNullOrEmpty(CurrentEmpSeq))
                errorStrb.Append(String.Format("CurrentEmpSeq is Empty"));

            errorStr = errorStrb.ToString();
            return String.IsNullOrEmpty(errorStr);

        }
    }
}